package cn.darkhorse.workflow.service.impl;

import cn.darkhorse.core.param.IUser;
import cn.darkhorse.workflow.auto.entity.BpmnSysPost;
import cn.darkhorse.workflow.auto.entity.BpmnSysUserPost;
import cn.darkhorse.workflow.auto.mapper.BpmnSysPostMapper;
import cn.darkhorse.workflow.auto.mapper.BpmnSysUserMapper;
import cn.darkhorse.workflow.auto.mapper.BpmnSysUserPostMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: mr.wang
 * @time: 2020/6/4 0004 10:58
 */
@Component("TaskGroupImpl")
public class TaskGroupImpl implements IUser {
	
	@Autowired
	BpmnSysPostMapper sysPostMapper;
	@Autowired
	BpmnSysUserMapper sysUserMapper;
	@Autowired
	BpmnSysUserPostMapper sysUserPostMapper;
	@Override
	public List<String> getUsers(String agrs,String relative) {
		List<String> users = new ArrayList<>();
		if(StringUtils.isBlank(relative)){
			return users;
		}
		//多岗位
		String[] params = relative.split(",");
		for(int i = 0 ;i<params.length;i++){
			QueryWrapper<BpmnSysPost> wrapper = new QueryWrapper<>();
			//wrapper.eq("post_code",agrs);
			//wrapper.eq("post_code",relative);
			wrapper.eq("post_code",params[i]);
			BpmnSysPost sysPost = sysPostMapper.selectOne(wrapper);
			if(sysPost!=null&&sysPost.getPostId()>0){
				QueryWrapper<BpmnSysUserPost> wrapper1 = new QueryWrapper<>();
				wrapper1.eq("post_id",sysPost.getPostId());
				List<BpmnSysUserPost> sysUserPosts = sysUserPostMapper.selectList(wrapper1);
				if(sysUserPosts!=null&&sysUserPosts.size()>0){
					for(BpmnSysUserPost li:sysUserPosts){
						users.add(sysUserMapper.selectById(li.getUserId()).getUserName());
					}
				}
			}
		}
		return users;
	}
	
	
	
	
	
	
}
